const joi = require('joi');

//用户注册登录的表单校验规则
const userName = joi
  .string()
  .pattern(/^[a-zA-Z0-9_-]{4,16}$/) // /^[a-zA-Z0-9_-]{4,16}$/; 字母数字下划线
  .required();
const password = joi
  .string()
  //密码强度正则，最少6位，包括至少1个大写字母，1个小写字母，1个数字，1个特殊字符
  // /^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/;
  .pattern(/^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/)
  .required();

exports.userCheck = {
  body: {
    userName,
    password,
  },
};

//课程查询参数的校验规则
const category = joi.string().required();
const page = joi.number().integer().required();
const size = joi.number().integer().required();
exports.findCourseCheck = {
  query: {
    category,
    page,
    size,
  },
};

//课程查询参数的校验规则
const title = joi.string();
const price = joi.number();
const id = joi.number().integer().required();
exports.updateCourseCheck = {
  query: {
    title,
    price,
    id,
  },
};

//课程删除参数的校验规则
exports.deleteCourseCheck = {
  query: {
    id,
  },
};

const course_img = joi.string().required();
const point = joi.number().required();

exports.createCourseCheck = {
  body: {
    title,
    course_img,
    point,
    price,
    category,
  },
};
